const query = require('./index')

class CommentModel {
  constructor () {}
// 插入数据到数据库
  static apply_insert (values) {
    const _sql = `INSERT INTO apply SET ?`
    return query(_sql, values)
  };

  static apply_insert_inst (values) {
    const _sql = `INSERT INTO apply_inst SET ?`
    return query(_sql, values)
  };


  static get_apply_all(){
    const _sql = `select * from apply`
    return query(_sql)
  }
  // 根据id进行查询
  // static apply_select_by_id (values) {
  //   const _sql = `select * from apply where id = ? `
  //   return query(_sql, values)
  // }
// 根据id进行查询
  // , (SELECT count(id) FROM t_like WHERE t_like.article_id = t_articles.id) as like_count, (SELECT count(id) FROM t_collections WHERE t_collections.article_id = t_articles.id) as collection_count, type_id FROM t_articles
  static apply_select_by_id(values) {
    const _sql = `SELECT * from apply WHERE id = ?`;
    return query(_sql, values);
  }

  //查询已参与
  static applyinsted_select_by_id(values) {
    const _sql = `select * from apply_inst where user_id=`+ values;
    return query(_sql, values);
  }

  static get_apply_top6_select(){
    const _sql = `SELECT * FROM apply WHERE apply_start = 'Y' order by id DESC limit 9`;
    return query(_sql);
  }

  static apply_insert_select(values){
    const _sql = "select * from apply where apply_title like concat('%','"+values.apply_title+"','%') and apply_xz like concat('%','"+values.apply_xz+"','%') and apply_start = 'Y'"
    return query(_sql, values);
  }
//   static apply_select_by_id (values) {
//     const _sql = `SELECT id, user_id, (SELECT username FROM user WHERE id = t_comments.user_id) as nikiname, (SELECT avatar FROM t_users WHERE id = t_comments.user_id) as avatar, article_id, content, DATE_FORMAT(created_time, '%Y/%m/%d %H:%i') as reply_time FROM t_comments WHERE id = ?`
//     return query(_sql, values)
//   } 
// 重复数据查询
static Duplicate_select(values){
  const _sql = 'select * from apply_inst where apply_id='+ values.apply_id+' and user_id= ' + values.user_id;
  return query(_sql, values);
}

static delect_apply_insert(values){
  const _sql = 'DELETE FROM apply_inst WHERE apply_id = ' + values
  return query(_sql, values);

}

}

module.exports = CommentModel